home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / SSAPI11.ZIP / SSTEST.ZIP / SSTESDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-26  |  7.5 KB  |  366 lines

  1. /******************************************************************************\
  2. *
  3. * (C) Copyright 1996 by Shetef Solutions Ltd.
  4. *
  5. * Address:
  6. *        Shetef Solutions Ltd.
  7. *        P. O. Box 7938
  8. *        Haifa 31078
  9. *        ISRAEL
  10. *
  11. * Email :     Support@shetef.com
  12. * WWW:        http://www.shetef.com
  13. * Tel:        +972-4-8260064
  14. * Fax:        +972-6-271210
  15. *
  16. \******************************************************************************/
  17.  
  18. // sstesdlg.cpp : implementation file
  19. //
  20.  
  21. #include "stdafx.h"
  22. #include "sstest.h"
  23. #include "sstesdlg.h"
  24.  
  25. #include "ssdll.h"
  26. #include "data.h"
  27.  
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char BASED_CODE THIS_FILE[] = __FILE__;
  31. #endif
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CAboutDlg dialog used for App About
  35.  
  36. class CAboutDlg : public CDialog
  37. {
  38. public:
  39.     CAboutDlg();
  40.  
  41. // Dialog Data
  42.     //{{AFX_DATA(CAboutDlg)
  43.     enum { IDD = IDD_ABOUTBOX };
  44.     //}}AFX_DATA
  45.  
  46. // Implementation
  47. protected:
  48.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  49.     //{{AFX_MSG(CAboutDlg)
  50.     virtual BOOL OnInitDialog();
  51.     //}}AFX_MSG
  52.     DECLARE_MESSAGE_MAP()
  53. };
  54.  
  55. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  56. {
  57.     //{{AFX_DATA_INIT(CAboutDlg)
  58.     //}}AFX_DATA_INIT
  59. }
  60.  
  61. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63.     CDialog::DoDataExchange(pDX);
  64.     //{{AFX_DATA_MAP(CAboutDlg)
  65.     //}}AFX_DATA_MAP
  66. }
  67.  
  68. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  69.     //{{AFX_MSG_MAP(CAboutDlg)
  70.         // No message handlers
  71.     //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CAboutDlg message handlers
  76.  
  77. BOOL CAboutDlg::OnInitDialog()
  78. {
  79.     CDialog::OnInitDialog();
  80.     CenterWindow();
  81.     
  82.     // TODO: Add extra about dlg initialization here
  83.     
  84.     return TRUE;  // return TRUE  unless you set the focus to a control
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CSstestDlg dialog
  89.  
  90. CSstestDlg::CSstestDlg(CWnd* pParent /*=NULL*/)
  91.     : CDialog(CSstestDlg::IDD, pParent)
  92. {
  93.     //{{AFX_DATA_INIT(CSstestDlg)
  94.         // NOTE: the ClassWizard will add member initialization here
  95.     //}}AFX_DATA_INIT
  96.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  97.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  98. }
  99.  
  100. void CSstestDlg::DoDataExchange(CDataExchange* pDX)
  101. {
  102.     CDialog::DoDataExchange(pDX);
  103.     //{{AFX_DATA_MAP(CSstestDlg)
  104.         // NOTE: the ClassWizard will add DDX and DDV calls here
  105.     //}}AFX_DATA_MAP
  106. }
  107.  
  108. BEGIN_MESSAGE_MAP(CSstestDlg, CDialog)
  109.     //{{AFX_MSG_MAP(CSstestDlg)
  110.     ON_WM_SYSCOMMAND()
  111.     ON_WM_PAINT()
  112.     ON_WM_QUERYDRAGICON()
  113.     ON_BN_CLICKED(IDC_DISABLE, OnDisable)
  114.     ON_BN_CLICKED(IDC_ENABLE, OnEnable)
  115.     ON_BN_CLICKED(IDC_FIX, OnFix)
  116.     ON_BN_CLICKED(IDC_HIDE, OnHide)
  117.     ON_BN_CLICKED(IDC_NOACCESS, OnNoaccess)
  118.     ON_BN_CLICKED(IDC_READONLY, OnReadonly)
  119.     ON_BN_CLICKED(IDC_RESET, OnReset)
  120.     ON_BN_CLICKED(IDC_SAFE, OnSafe)
  121.     ON_BN_CLICKED(IDC_SSINIT, OnSsinit)
  122.     ON_BN_CLICKED(IDC_SSTERMINATE, OnSsterminate)
  123.     ON_BN_CLICKED(IDC_UNFIX, OnUnfix)
  124.     ON_WM_CLOSE()
  125.     //}}AFX_MSG_MAP
  126. END_MESSAGE_MAP()
  127.  
  128.  
  129. void TestErrMsg(int err) {
  130.     CHAR buf[MAX_PATH];
  131.  
  132.     switch (err) {
  133.         case SSERR_NOERROR:
  134.             wsprintf(buf, "No error");
  135.             break;
  136.         case SSERR_DLL_ALREADY_INITIALIZED:
  137.             wsprintf(buf, "DLL already initialized");
  138.             break;
  139.         case SSERR_DLL_NOT_INITIALIZED:
  140.             wsprintf(buf, "DLL not initialized yet");
  141.             break;
  142.         case SSERR_NOT_WIN95_OS            :
  143.             wsprintf(buf, "We are not running currently on a windows 95 os");
  144.             break;
  145.         case SSERR_FAILED_LOADING_VXD    :
  146.             wsprintf(buf, "Failed loading VxD");
  147.             break;
  148.         case SSERR_VXD_ALREADY_LOADED    :
  149.             wsprintf(buf, "VxD already loaded");
  150.             break;
  151.         case SSERR_FAILED_UNLOADING_VXD    :
  152.             wsprintf(buf, "failed unloading VxD");
  153.             break;
  154.         case SSERR_SS_NOT_INITIALIZED    :
  155.             wsprintf(buf, "SSDLL was not initialized");
  156.             break;
  157.         case SSERR_FAILED_FIXING        :
  158.             wsprintf(buf, "Failed fixing the application");
  159.             break;
  160.         case SSERR_FAILED_UNFIXING        :
  161.             wsprintf(buf, "Failed un fixing the application");
  162.             break;
  163.         default:
  164.             wsprintf(buf, "What, I do not know this error code!");
  165.             break;
  166.     }
  167.     AfxMessageBox(buf);
  168. }
  169.  
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CSstestDlg message handlers
  172.  
  173. BOOL CSstestDlg::OnInitDialog()
  174. {
  175.     CDialog::OnInitDialog();
  176.     CenterWindow();
  177.  
  178.     // Add "About..." menu item to system menu.
  179.  
  180.     // IDM_ABOUTBOX must be in the system command range.
  181.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  182.     ASSERT(IDM_ABOUTBOX < 0xF000);
  183.  
  184.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  185.     CString strAboutMenu;
  186.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  187.     if (!strAboutMenu.IsEmpty())
  188.     {
  189.         pSysMenu->AppendMenu(MF_SEPARATOR);
  190.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  191.     }
  192.     
  193.     // TODO: Add extra initialization here
  194.     
  195.     return TRUE;  // return TRUE  unless you set the focus to a control
  196. }
  197.  
  198. void CSstestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  199. {
  200.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  201.     {
  202.         CAboutDlg dlgAbout;
  203.         dlgAbout.DoModal();
  204.     }
  205.     else
  206.     {
  207.         CDialog::OnSysCommand(nID, lParam);
  208.     }
  209. }
  210.  
  211. // If you add a minimize button to your dialog, you will need the code below
  212. //  to draw the icon.  For MFC applications using the document/view model,
  213. //  this is automatically done for you by the framework.
  214.  
  215. void CSstestDlg::OnPaint() 
  216. {
  217.     if (IsIconic())
  218.     {
  219.         CPaintDC dc(this); // device context for painting
  220.  
  221.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  222.  
  223.         // Center icon in client rectangle
  224.         int cxIcon = GetSystemMetrics(SM_CXICON);
  225.         int cyIcon = GetSystemMetrics(SM_CYICON);
  226.         CRect rect;
  227.         GetClientRect(&rect);
  228.         int x = (rect.Width() - cxIcon + 1) / 2;
  229.         int y = (rect.Height() - cyIcon + 1) / 2;
  230.  
  231.         // Draw the icon
  232.         dc.DrawIcon(x, y, m_hIcon);
  233.     }
  234.     else
  235.     {
  236.         CDialog::OnPaint();
  237.     }
  238. }
  239.  
  240. // The system calls this to obtain the cursor to display while the user drags
  241. //  the minimized window.
  242. HCURSOR CSstestDlg::OnQueryDragIcon()
  243. {
  244.     return (HCURSOR) m_hIcon;
  245. }
  246.  
  247. void CSstestDlg::OnDisable() 
  248. {
  249.     int rc = SSDisable();
  250.     if (rc) {
  251.         TestErrMsg(rc);
  252.     }
  253.     
  254. }
  255.  
  256. void CSstestDlg::OnEnable() 
  257. {
  258.     int rc = SSEnable();
  259.     if (rc) {
  260.         TestErrMsg(rc);
  261.     }
  262.     
  263. }
  264.  
  265. void CSstestDlg::OnFix() 
  266. {
  267.     int rc = SSFixApplication();
  268.     if (rc) {
  269.         TestErrMsg(rc);
  270.     }
  271.     
  272. }
  273.  
  274. void CSstestDlg::OnHide() 
  275. {
  276.     CData dlg;
  277.     int rc;
  278.  
  279.     if (dlg.DoModal() == IDOK) {
  280.         rc = SSSetHide(dlg.m_Data, dlg.m_bSubDir, dlg.m_bExclude);
  281.         if (rc) {
  282.             TestErrMsg(rc);
  283.         }
  284.     }
  285.     
  286. }
  287.  
  288. void CSstestDlg::OnNoaccess() 
  289. {
  290.     CData dlg;
  291.     int rc;
  292.  
  293.     if (dlg.DoModal() == IDOK) {
  294.         rc = SSSetNoAccess(dlg.m_Data, dlg.m_bSubDir, dlg.m_bExclude);
  295.         if (rc) {
  296.             TestErrMsg(rc);
  297.         }
  298.     }
  299. }
  300.  
  301. void CSstestDlg::OnReadonly() 
  302. {
  303.     CData dlg;
  304.     int rc;
  305.  
  306.     if (dlg.DoModal() == IDOK) {
  307.         rc = SSSetReadOnly(dlg.m_Data, dlg.m_bSubDir, dlg.m_bExclude);
  308.         if (rc) {
  309.             TestErrMsg(rc);
  310.         }
  311.     }
  312. }
  313.  
  314. void CSstestDlg::OnReset() 
  315. {
  316.     SSResetAccessRestrictions();
  317.     
  318. }
  319.  
  320. void CSstestDlg::OnSafe() 
  321. {
  322.     CData dlg;
  323.     int rc;
  324.  
  325.     if (dlg.DoModal() == IDOK) {
  326.         rc = SSSetSafeTask(dlg.m_Data);
  327.         if (rc) {
  328.             TestErrMsg(rc);
  329.         }
  330.     }
  331. }
  332.  
  333. void CSstestDlg::OnSsinit() 
  334. {
  335.     int rc = SSInit();
  336.         if (rc) {
  337.         TestErrMsg(rc);
  338.     }
  339. }
  340.  
  341. void CSstestDlg::OnSsterminate() 
  342. {
  343.     int rc = SSTerminate();
  344.     if (rc) {
  345.         TestErrMsg(rc);
  346.     }
  347. }
  348.  
  349. void CSstestDlg::OnUnfix() 
  350. {
  351.     int rc = SSUnFixApplication();
  352.     if (rc) {
  353.         TestErrMsg(rc);
  354.     }
  355. }
  356.  
  357. void CSstestDlg::OnOK() 
  358. {
  359.     CDialog::OnOK();
  360. }
  361.  
  362. void CSstestDlg::OnClose() 
  363. {
  364.     CDialog::OnClose();
  365. }
  366.